import React, {Component} from 'react';
import {
    Flex,
    Icon,
    Tabs,
    NavBar,
    Popover,
    WingBlank,
    WhiteSpace,
    Carousel,
    Modal,
    Grid,
    List,
    Button,
    Toast,
    Badge
} from 'antd-mobile';
import { connect } from 'dva';
import MyListView from '../../components/MyListView/MyListView';
import Moment from 'moment';
import MyScroll from '../../components/MyScroll/MyScroll';
import NoLazyImg from '../../components/NoLazyImg/NoLazyImg';
import NavTopBar from '../../components/NavTopBar/NavTopBar';
import MyListViewLz from '../../components/MyListViewLz/MyListViewLz';
import {routerRedux} from "dva/router";
import {checkbox} from './findPeople.less';
import {findIndex, fenlei, noguanzhu} from './findIndex.less';
import  renwu from'../../assets/svg/renwu.svg';
import  caidan from'../../assets/svg/caidan.svg';
import dianzan from '../../assets/svg/dianzan.svg';
import dianzan1 from '../../assets/svg/dianzan1.svg';
import fenxiang1 from '../../assets/svg/fenxiang1.svg';
import PersonHomeItem from './personHomeItem';
import pinglun from '../../assets/svg/pinglun.svg';
import share from '../../assets/svg/share.svg';
import sanjiaoup from "../../assets/svg/sanjiaoup.svg";
import sanjiaod from "../../assets/svg/sanjiaod.svg";
import {evalute_madel} from "../evaluate/EvaluateListItem.less";
import {person} from "./personHome.less";
import {myHead, myHeadTwo} from "../my/myHeader.less";




class MyArticle extends Component {
    constructor(props){
        super(props);
        this.state={
            audit:0,
            tabs: [
                { title: '已发布',id:"a" },
                { title: '投稿中',id:"b" },
                { title: '被驳回',id:"c" },
            ]
        }
        this.AlloyTouch = null;
        this.page=0;

    }

    componentDidMount(){
        this.refresh();
    }
    refresh = () => {
        console.log(parseInt(this.state.audit))
        if (parseInt(this.state.audit)==0){
            return this.props.dispatch({ type: 'findOthers/myArticleApiEFF',obj:{audit:1,pageNo:1} });
        }else if (parseInt(this.state.audit)==2){
            return this.props.dispatch({ type: 'findOthers/myArticleApiEFF',obj:{audit:3,pageNo:1} });
        }else {
            return this.props.dispatch({ type: 'findOthers/myArticleApiEFF',obj:{audit:0,pageNo:1} });
        }
    }

    loadMore = () => {
        if (parseInt(this.state.audit)==0){
            return this.props.dispatch({ type: 'findOthers/myArticleApiEFF',obj:{audit:1,pageNo:this.props.findOthers.pageNo+1} });
        }else if (parseInt(this.state.audit)==2){
            return this.props.dispatch({ type: 'findOthers/myArticleApiEFF',obj:{audit:3,pageNo:this.props.findOthers.pageNo+1} });
        }else {
            return this.props.dispatch({ type: 'findOthers/myArticleApiEFF',obj:{audit:0,pageNo:this.props.findOthers.pageNo+1} });
        }
    }
    getAlloyTouch = (AT) =>{
        this.AlloyTouch = AT;
    };
    renderContent = tab =>{
        const {dispatch} = this.props;
        const audit=parseInt(this.state.audit);
        const { articleList } =this.props.findOthers;
        console.log(articleList)
        if(articleList&&articleList.length>0){
            return <MyListViewLz
                style={{height:"100%"}}
                refresh={ this.refresh }
                loadMore={ this.loadMore }
                kid={tab.id+"a"}
                hasMore={ this.props.findOthers.pageNo * this.props.findOthers.pageSize < this.props.findOthers.totalRows  }
                // itemWrapperClass={ goods_list }
                // bottomStyle={ layoutType == true ? {} : { marginTop:"0.2rem", paddingTop:'0rem' } }
                renderItem={(v,i,a)=>{
                    return <PersonHomeItem audit={audit} dispatch={dispatch} id={-1}  v={v} key={i}  refresh={ this.refresh }></PersonHomeItem>
                }}
                data={ articleList }
            ></MyListViewLz>
        }else{
            return <div className={noguanzhu}>
                <div className="guanzhuLogo"></div>
                <div >没有相应文章!</div>
            </div>
        }
    }
    render() {
        const tabs=this.state.tabs;
        const audit=parseInt(this.state.audit);
        const {dispatch} = this.props;
        const { articleList } =this.props.findOthers;
        console.log(this.state.audit)
        return (
            <Flex direction="column"
                  style={{height:"100%"}}>
                <NavTopBar dispatch={this.props.dispatch} title='我的文章'></NavTopBar>
                <Tabs tabs={tabs}
                      swipeable={false} initialPage={0} page={this.state.audit}
                      onChange={(tab, index) => {
                          this.setState({
                              audit:index
                          })
                          // this.props.dispatch(routerRedux.replace(`/myArticle/${index}`));
                          //this.refresh();
                          if (index==0){
                              return this.props.dispatch({ type: 'findOthers/myArticleApiEFF',obj:{audit:1,pageNo:1} });
                          }else if (index==2){
                              return this.props.dispatch({ type: 'findOthers/myArticleApiEFF',obj:{audit:3,pageNo:1} });
                          }else {
                              return this.props.dispatch({ type: 'findOthers/myArticleApiEFF',obj:{audit:0,pageNo:1} });
                          }
                      }}
                      renderTabBar={props => <Tabs.DefaultTabBar {...props} page={3} />}
                >
                    {this.renderContent}
                </Tabs>
            </Flex>
        )


    }
}

export default connect(({ findOthers }) => ({ findOthers}))(MyArticle);
